﻿namespace XamlCop
{
    using System.Windows;
    using System.Windows.Forms;
    using System.IO;
    using Microsoft.Xaml.Tools.XamlDom;
    using System.Collections;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void buttonLoadProjectFile_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            dialog.Filter = "C# Projects (*.csproj)|*.csproj|VB Projects (*.vbproj)|*.vbproj";
            DialogResult result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                textBoxProjectFile.Text = dialog.FileName;    
                if (File.Exists(textBoxProjectFile.Text))
                {
                    this.buttonAnalyseXaml.IsEnabled = true;
                }
            }
        }

        private void buttonAnalyseXaml_Click(object sender, RoutedEventArgs e)
        {
            this.Cursor = System.Windows.Input.Cursors.Wait;
            textBoxBindingErrors.Text += BindingFinder.Program.GetBindingErrors(textBoxProjectFile.Text);
        }

        private void textBoxBindingErrors_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            this.Cursor = System.Windows.Input.Cursors.Arrow;
            this.buttonAnalyseXaml.IsEnabled = false;
        }
    }
}
